'''
Created on 09.06.2013

@author: Michael (Cornelius hat auch was gemacht)
'''

'''
Represents a user.
'''
class User(object):
    
    __name = None
    __userID = 0
    __charID = 0
    __bombUp = 1
    __speedUp = 1
    __strengthUp = 1
    __bombsOut = 0
    __maxUP = 9
    __isDead = False
    
    pos = (0,0)

    def __init__(self, name, userID, charID):
        self.__name = name
        self.__userID = userID
        self.__charID = charID
        
    def setInitPos(self, fieldSize):
        if self.__userID == 0:
            self.pos = (1,1)
        elif self.__userID == 1:
            self.pos = (fieldSize[0]-2, 1)
        elif self.__userID == 2:
            self.pos = (1, fieldSize[1]-2)
        elif self.__userID == 3:
            self.pos = (fieldSize[0]-2,fieldSize[1]-2)
        else:
            print 'ERROR: userID != 0-3 but ' + str(self.__userID)

    # returns avatar or field image according to the given state.
    # state = none -> avatar will be returned
    # state = 1..3 -> walk animation images
    def getCharImage(self, state):
        if state is None:
            return './images/char0' + str(self.__charID) + '/' + str(self.__userID+1) + '.png'
        return './images/char0' + str(self.__charID) + '/' + str(self.__userID+1) + '_' + str(state) + '.png'
    
    def getName(self):
        return self.__name
    
    def getUserID(self):
        return self.__userID
    
    def getCharID(self):
        return self.__charID
    
    def canPlaceBomb(self):
        if self.__bombsOut < self.__bombUp:
            return True
        return False
    
    def die(self):
        self.__isDead = True
        self.pos = (0,0)
        
    def isDead(self):
        return self.__isDead
    
    def bombPlaced(self):
        self.__bombsOut += 1
    
    def bombDetonated(self):
        self.__bombsOut -= 1
    
    def upgradeBomb(self):
        self.__bombUp += 1
        if self.__bombUp > self.__maxUP:
            self.__bombUp = self.__maxUP
        
    def getBombStat(self):
        return self.__bombUp
    
    def upgradeSpeed(self):
        self.__speedUp += 1
        if self.__speedUp > self.__maxUP:
            self.__speedUp = self.__maxUP
        
    def getSpeedStat(self):
        return self.__speedUp
    
    def upgradeStrength(self):
        self.__strengthUp += 1
        if self.__strengthUp > self.__maxUP:
            self.__strengthUp = self.__maxUP
        
    def getStrengthStat(self):
        return self.__strengthUp
    
    def setCharId(self, ID):
        self.__charID = ID
        
    def setUserId(self, ID):
        self.__userID = ID
    
    def setName(self, name):
        self.__name = name
    